
var a = 10;
function f(){
    var message = "Hello World!";
    return message;
}

function fx(bInit: boolean){
    if(bInit)
        var x = 10;
    return x;
}

document.write(`<p>condition=true,x = ${fx(true)}</p>`);
document.write(`<p>condition=false,x = ${fx(false)}</p>`);

function ptf(i){
    document.write(`<p>i = ${i}</p>`);
}
for(var i=0; i<10; i++){
    setTimeout(ptf(i), 50);
}

for(var i=0; i<10; i++){
    setTimeout(function(){
        //document.write(`<p>i = ${i}</p>`);
    }, 
    100*i);
}

function flet(condition, x){
    if(condition){
        let x = 100;
        return x;
    }
    return x;
}
document.write(`<p>${flet(true, 0)}</p>`); // 100
document.write(`<p>${flet(false, 0)}</p>`);// 0

const NUM_PI = 3.1415926;
//NUM_PI = 0;   // Error,

const kitty = {
    name: "Aurora",
    numLives: NUM_PI,
}
/*
kitty = {
    name: "Danielle",
    numLives: NUM_PI,
}*/
kitty.name = "Rory";    // 可以对const对象的内部进行修改！！

let input = [1, 2];
let [first, second] = input
document.write(`<p>${first},${second}</p>`)

let [first1, ...second1] = [1,2,3,4];
document.write(`<p>first1=${first1}</p>`)
document.write(`<p>second1=${second1}</p>`)

let [first2] = [4,5,6,];
document.write(`<p>first2=${first2}</p>`)

let [,,third] = [4,5,6,7];
document.write(`<p>third=${third}</p>`)

let xyz = {
    x: "func",
    y: 123,
    z: "write",
}
let {x, y} = xyz;
document.write(`<p>xyz_x=${x}</p>`);
document.write(`<p>xyz_y=${y}</p>`);

document.write(`<p>属性重命令</p>`);
let {x:newnamex, y:newnamey} = xyz;
document.write(`<p>newnamex=${newnamex}</p>`);
document.write(`<p>newnamey=${newnamey}</p>`);
let newNamex = xyz.x;
let newNamey = xyz.y;
// 加上类型声明
//let {newNamex, newNamey}:{newNamex:string,newNamey:number} = xyz;

function keepWholeObject(wholdObj: {a:string, b?:number}){
    let {a,b=100} = wholdObj;
}

type C = {a:string, b?: number};
let newType: C;
function fNewType({a, b}: C): void {
    // ...
}

















